;GW Instek AC/DC power supply ASR-2000 Series
; 2/27/23  Rev C   GBY   Update logging to use :SOUR:READ? and get lots at once.
; 7/27/22  Rev B   GBY   Updates to existing Setup control, added operating mode drop down, SCPI Error text box.
; 5/30/22  Rev A   GBY   Originate

;Tested with 
;   TC 2.06 
;   GW Instek ASR-2100 with FW 1.20
;   Over LAN
;   USB is via a COM port so could add to this file to get USB working.
;   Should work with ASR2050 and might work with ASR-3000 series that uses same FW
;   Over LAN minimum reliable sampling interval is 60 mSec for 6 logged values per sample time.
;   Over LAN minimum reliable sampling intervale is 20 mSec using :SOUR:READ? to get everything in one reply.
;   But, the ARS-2000 only seems to calc new data 5 times/sec so sampling faster than 0.1 sec not needed

; There are 2 power supplies in the GW Instek ASR-2000 family which uses 100-240 Vac single phase input.
; Model				VA		Vac low		Arm Low		Vdc Low		Adc Low
; ASR-2050	 		1000W	0~175Vrms	0~5Arms		-250~250Vdc	5Adc
; ASR-2100			500W	0~175Vrms	0~10Arms	-250~250Vdc	10Adc
; In the high range the voltages are double and the currents are halved.

; There are 3 power supplies in the GW Instek ASR-3000 family which uses 200 to 240 Vac single phase input.
; Model				VA		Vac low		Arm Low		Vdc Low		Adc Low
; ASR-3200	 		1000W	0~200Vrms	0~20Arms	-285~285Vdc	20Adc
; ASR-3300			500W	0~200Vrms	0~30Arms	-285~285Vdc	30Adc
; ASR-3400			500W	0~200Vrms	0~40Arms	-285~285Vdc	40Adc
; In the high range the voltages are double and the currents are halved.

#metadef
#idstring GW-INSTEK,ASR-3200
#name GW Instek ASR-3200
#handle ASR3200
#replaceText MaxVoltageRMS 400
#replaceText MaxVoltageDC 570
#replaceText MaxCurrentRMS 10.0
#replaceText MaxFreq 1000

#metadef
#idstring GW-INSTEK,ASR-3300
#name GW Instek ASR-3300
#handle ASR3300
#replaceText MaxVoltageRMS 400
#replaceText MaxVoltageDC 570
#replaceText MaxCurrentRMS 15.0
#replaceText MaxFreq 1000

#metadef
#idstring GW-INSTEK,ASR-3400
#name GW Instek ASR-3400
#handle ASR3200
#replaceText MaxVoltageRMS 400
#replaceText MaxVoltageDC 570
#replaceText MaxCurrentRMS 20.0
#replaceText MaxFreq 1000

#metadef
#idstring GW-INSTEK,ASR-2050
#name GW Instek ASR-2050
#handle ASR2050
#replaceText MaxVoltageRMS 350
#replaceText MaxVoltageDC 500
#replaceText MaxCurrentRMS 2.6
#replaceText MaxFreq 1000

#metadef
#idstring GW-INSTEK,ASR-2100
#name GW Instek ASR-2100
#handle ASR2100
#replaceText MaxVoltageRMS 350
#replaceText MaxVoltageDC 500
#replaceText MaxCurrentRMS 5.25
#replaceText MaxFreq 1000

#meta
#idString GW-INSTEK,ASR-2100
#name GW-Instek ASR-2100
#handle ASR2100
#port 2268
; Alternate port types: comnobaud or com, com lets the user define baudrate on the "Load devices" page
#author gby
#notes GW Instek ASR-2000 series are AC power supplies that can also output DC. This driver uses Ethernet communications option with socket connection.  A modified form of this device file might work with USB, serial, or optional GPIB communications and probabaly works with GW Instek ASR-3000 series supplies.

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6) 
; Format: #value ColumnName Unit Format {Selector}
; Selector is only used when column layout varies with mode, this often require the use of #cmdMode
; :SOUR:READ? returns groupd of measurements.
;  <Vrms>,<Vavg>,<Vmax>,<Vmin>,<Irms>,<Iavg>,<Imax>,<Imin>,<IpkH>,<P>,<S>,<Q>,<PF>,<CF>,<THDv>,<THDi>,<Freq>
;  Note all values defined in all modes.  Like no PF in DC modes
#value Vrms Vrms D4
#value Vdc Vdc D4
#value Vmax V D4
#value Vmin V D4
#value Irms Arms D4
#value Idc Adc D4
#value Imax A D4
#value Imin A D4
#value IdpkH A D4
#value P Watt D4
#value S Watt D4
#value Q Watt D4
#value PF - D4
#value CF - D4
#value THDv % D4
#value THDi % D4
#value Freq Hz D4

; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; Number of returned values must match number of columns defined with #value
; This is a single line command
#askValues :SOUR:READ?
;#askValues :MEAS:SCAL:VOLT:RMS?;:MEAS:SCAL:VOLT:AVER?;:MEAS:SCAL:CURR:RMS?;:MEAS:SCAL:CURR:AVER?;:meas:scal:POW?

; Format of answer: f=float, u=remove trailing letters, x=skip, *=Zero upper case values if this value is 0
;#askValuesReadFormat 

; Accept this delay when reading values (seconds)
#readingDelay 2

; Mode change have a longer delay on reading values (seconds)
#modeChangeDelay 10


; String to ask about actual meter mode, it is mostly used for DMM's
; This is a single line command
;#askMode 


; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
;#mayModifyMode 


; Prepare the meter to response to #askValues
;#prepareSample arm:sour imm;:arm:count 1;:trig:sour imm;:trig:count 1;:trig:samp:count 1;init

; Initial commands to meter when establishing connection, used to disable local control
;#initCmd  

; Final command to meter before breaking connection, used to restore local control
;#finalCmd 

; Used to turn output off for power supplies, generators and electronic loads
;#outputOff 

;************   Programming Interface **********

#interfaceType PS

; **********  Setup Popup   ***********

#cmdSetup number Volt_ac Settings
; ac voltage
:read: :SOUR:VOLT:LEV:IMM:AMPL?
:write: :SOUR:VOLT:LEV:IMM:AMPL
:tip: NA in DC-INT mode.
Vrms  0 MaxVoltageRMS

#cmdSetup number Volt_dc Settings
; dc voltage
:read: :SOUR:VOLT:LEV:IMM:OFFS?
:write: :SOUR:VOLT:LEV:IMM:OFFS
:tip: NA in AC only modes.
Vdc  0 MaxVoltageDC

#cmdSetup number Current_rms Settings
:read: :SOUR:CURR:LIM:RMS:AMPL?
:write: :SOUR:CURR:LIM:RMS:AMPL
:tip: Max current limited at higher voltages by max power limit.
Arms  0 MaxCurrentRMS

#cmdSetup number AC_Frequency Settings
:read: :SOUR:FREQ:IMM?
:write: :SOUR:FREQ:IMM
:tip: NA in -SYNC modes.
Hz  0 MaxFreq

;#cmdSetup number Voltage Protect_Limits
;:read: SOUR:VOLT:PROT:LEVEL?
;:write: SOUR:VOLT:PROT:LEVEL
;Vdc  MinPVolt MaxPVolt

;#cmdSetup number Current Protect_Limits
;:read: SOUR:CURR:PROT:LEVEL?
;:write: SOUR:CURR:PROT:LEVEL
;Adc  MinPCurrent MaxPCurrent

#cmdSetup radio Range
:read: :SOUR:VOLT:RANG?
:update: Volt_rms
:write: :SOUR:VOLT:RANG
175_Vac 100
350_Vac 200
:tip: Range is 0-175 or 0-350 Vac.  Full current nominals up to 100 or 200 Vac.

#cmdSetup buttonsOn Output
:read: :OUTP:STAT?
:write: :OUTP:STAT 
:color: (0,255,0)
:tip: Turn output on or off
:updatealloff:
Off 0
On 1

#cmdSetup radio Vac_Preset
; Sets Vdc to 0 and then Vac to value.
:read: SOUR:VOLT:LEVEL:IMM:AMPL?
:update: Volt_dc, Volt_ac, Vdc_Preset
:write: :SOUR:VOLT:LEV:IMM:OFFS 0;SOUR:VOLT:LEVEL:IMM:AMPL
:tip: Sets Vdc to 0 and then Vac to value.
0.0 0
35.4 35.4
120 120
240 240
265 265

#cmdSetup radio Vdc_Preset
; Sets Vac to 0 and then Vdc to value.
:read: SOUR:VOLT:LEVEL:IMM:OFFS?
:update: Volt_dc, Volt_ac, Vac_Preset
:write: SOUR:VOLT:LEVEL:IMM:AMPL 0;:SOUR:VOLT:LEV:IMM:OFFS
:tip: Sets Vac to 0 and then Vdc to value.
0.0 0
50 50
170 170
340 340
375 375

#cmdSetup comboboxHot Op_Mode
:write: :SOUR:MODE
:read: :SOUR:MODE?
:tip: Set operating mode of supply.  Note: In some modes some of the items are no longer valid and the instrument will display SCPI Error box.
AC+DC-INT   ACDC-INT
AC-INT      AC-INT
DC-INT      DC-INT
AC+DC-EXT   ACDC-EXT
AC-EXT      AC-EXT
AC+DC-ADD   ACDC-ADD
AC-ADD      AC-ADD
AC+DC-SYNC  ACDC-SYNC
AC-SYNC     AC-SYNC

#cmdSetup checkbox Freq_Source
:read: :input:sync:source?
:readmath: match(value, "EXT")
:write: :input:sync:source
:tip: Only works in AC+DC-SYNC and AC-SYNC modes.
Ext 0 1

#cmdSetup text Clear_SCPI_Err
:read: :SYST:ERR?
; Argument of ("") allows sending nothing after the command
:write: *IDN? ("")
:tip: Click multiple times to clear error box on instrument screen.
